home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 62
/
Volume 62 - JOGO DISK .iso
/
Games
/
penguin_dinner.swf
/
scripts
/
__Packages
/
classes
/
game
/
Hero.as
< prev
next >
Wrap
Text File
|
2008-03-17
|
3KB
|
124 lines
class classes.game.Hero extends MovieClip
{
function Hero()
{
super();
this.food = [];
this.setState(classes.const.Direction.DOWN);
this.queue = new classes.game.CharActionQueue();
}
function giveFood($food)
{
var _loc2_ = 0;
while(_loc2_ < this.food.length)
{
if(this.food[_loc2_] == $food)
{
this.food.splice(_loc2_,1);
this.setState();
return true;
}
_loc2_ = _loc2_ + 1;
}
return false;
}
function takeReadyFood($foodType)
{
if($foodType == classes.game.Food.TYPE_NONE || this.food.length == 2)
{
return false;
}
this.food.push($foodType);
this.setState();
return true;
}
function clearFood()
{
if(this.food.length == 0)
{
return undefined;
}
classes.core.SoundManager.getInstance().startSound("trashcan");
this.food = [];
this.setState();
}
function update()
{
var _loc2_ = this.queue.getCoords();
this._x = _loc2_.x;
this._y = _loc2_.y;
var _loc5_ = Math.abs(_loc2_.dx);
var _loc4_ = Math.abs(_loc2_.dy);
if(_loc5_ + _loc4_ > 0.1)
{
var _loc3_ = undefined;
if(_loc5_ > _loc4_)
{
if(_loc2_.dx > 0)
{
_loc3_ = classes.const.Direction.RIGHT;
}
else
{
_loc3_ = classes.const.Direction.LEFT;
}
}
else if(_loc2_.dy > 0)
{
_loc3_ = classes.const.Direction.DOWN;
}
else
{
_loc3_ = classes.const.Direction.UP;
}
this.setState(_loc3_);
}
this.targetObjReached = _loc2_.end;
}
function moveTo(tileX, tileY)
{
this.targetTile = new classes.math.Tile(tileX,tileY,0,0,0);
var _loc2_ = new classes.math.Tile(Math.floor(this._x / classes.math.Tile.SIZE) - classes.math.Tile.DX,Math.floor(this._y / classes.math.Tile.SIZE) - classes.math.Tile.DY,0,0,0);
this.queue.setTargetTile(_loc2_,this.targetTile,classes.game.GameData.__get__HERO_SPEED());
}
function setState($direction)
{
if($direction != undefined)
{
this.prevDirection = $direction;
}
else
{
$direction = this.prevDirection;
}
var _loc2_ = "walking_";
switch($direction)
{
case classes.const.Direction.UP:
_loc2_ += "up_";
break;
case classes.const.Direction.DOWN:
_loc2_ += "down_";
break;
case classes.const.Direction.RIGHT:
_loc2_ += "side_";
this._xscale = 100;
break;
case classes.const.Direction.LEFT:
_loc2_ += "side_";
this._xscale = -100;
}
_loc2_ += String(this.food.length);
this.gotoAndStop(_loc2_);
switch(this.food.length)
{
case 1:
this.plate_0.gotoAndStop(this.food[0]);
break;
case 2:
this.plate_0.gotoAndStop(this.food[0]);
this.plate_1.gotoAndStop(this.food[1]);
}
}
}